<?php

/**
 * @Author: king
 * @Date:   2019-05-11 21:44:31
 * @Last Modified by:   king
 * @Last Modified time: 2019-05-11 21:46:19
 */
namespace App\Models\Api;
use App\Models\Api\Base;
use Cache;

/**
 * 骰子-》撒比恩象征 模型类
 * Class DivinationTips
 * @package app\common\model
 */
class DivinationSabienTips extends Base
{
    protected $table = 'sabien';// 定义表名

    /** 获取详情
     * @param array $map
     * @return array|bool|false|mixed|\PDOStatement|string|\think\Model
     */
    public function getDetail($map)
    {
        $key = $map['sign'] . '-' . floor($map['deg']);
        $result = false;
        if ($this->cache_on >= 1 && Cache::has('sabien_' . $key)) {
            $result = Cache::get('sabien_' . $key);
        }
        if ($result === false) {
            try {
                $result = $this->select('text')
                    ->where('sign_deg', $key)
                    ->first();
            } catch (\Exception $e) {
                // 错误信息写入日志
                \Log::info('获取骰子词条错误:' . '[' . $key . ']');
            }
            $result = json_decode(json_encode($result, true), true);

            if ($this->cache_on >= 1) {
                Cache::set('sabien_' . $key, $result, 86400 * 7);
            }
        }

        return $result;
    }
}
